package com.leyou.upload.controller;

import com.leyou.upload.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author hcz
 * @describtion TODO
 * @date 2019-06-25 18:48
 */
@RestController
public class UploadController {

    @Autowired
    private UploadService uploadService;

    @PostMapping("image")
    public ResponseEntity<String> uploadImage(
            @RequestParam("file")MultipartFile file){
        //返回200，并携带url路径
        return ResponseEntity.ok(this.uploadService.upload(file));
    }

    /**
     * 生成签名并返回
     * @return
     */
    @GetMapping("signature")
    public ResponseEntity<Map<String,Object>> getAliSignature(){
        return ResponseEntity.ok(uploadService.getSignature());
    }

}
